package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.Terminal;
import com.ktgj.flight.service.ITerminalService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 航站楼Controller
 * 
 * @author ruoyi
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/flightTerminal")
public class TerminalController extends BaseController
{
    @Autowired
    private ITerminalService terminalService;

    /**
     * 查询航站楼列表
     */
    //@PreAuthorize(hasPermi = "flight:terminal:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Terminal terminal)
    {
        startPage();
        List<Terminal> list = terminalService.selectTerminalList(terminal);
        return getDataTable(list);
    }

    /**
     * 导出航站楼列表
     */
    @PreAuthorize(hasPermi = "flight:terminal:export")
    @Log(title = "航站楼", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Terminal terminal) throws IOException
    {
        List<Terminal> list = terminalService.selectTerminalList(terminal);
        ExcelUtil<Terminal> util = new ExcelUtil<Terminal>(Terminal.class);
        util.exportExcel(response, list, "航站楼数据");
    }

    /**
     * 获取航站楼详细信息
     */
    //@PreAuthorize(hasPermi = "flight:terminal:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map)
    {
        Long terminalId = Long.valueOf(map.get("terminalId").toString());
        return AjaxResult.success(terminalService.selectTerminalById(terminalId));
    }

    /**
     * 新增航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:add")
    @Log(title = "航站楼", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Terminal terminal)
    {
        return toAjax(terminalService.insertTerminal(terminal));
    }

    /**
     * 修改航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:edit")
    @Log(title = "航站楼", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Terminal terminal)
    {
        return toAjax(terminalService.updateTerminal(terminal));
    }

    /**
     * 删除航站楼
     * @param map
     * @return
     */
    @PostMapping("/deleteTerminalById")
    public AjaxResult deleteTerminalById(@RequestBody Map<String, Object> map) {
        Long terminalId = Long.valueOf(map.get("terminalId").toString());
        return toAjax(terminalService.deleteTerminalById(terminalId));
    }

    /**
     * 删除航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:remove")
    @Log(title = "航站楼", businessType = BusinessType.DELETE)
	@DeleteMapping("/{terminalIds}")
    public AjaxResult remove(@PathVariable Long[] terminalIds)
    {
        return toAjax(terminalService.deleteTerminalByIds(terminalIds));
    }
}
